package com.qiaotongtianxia.loans.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.NestedScrollView;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.qiaotongtianxia.loans.R;
import com.qiaotongtianxia.loans.bean.RefundBean;
import com.qiaotongtianxia.loans.net.Api;
import com.qiaotongtianxia.loans.util.CommonUtils;
import com.qiaotongtianxia.loans.util.Constants;
import com.qiaotongtianxia.loans.views.BaseTextView;
import com.qiaotongtianxia.loans.views.DragLayout;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by lisen on 2017/12/18.
 *
 * @author lisen < 4533548588@qq.com >
 */

@SuppressWarnings("all")
public class LicenceActivity extends BaseActivity implements DragLayout.DragListener{
    @BindView(R.id.tv_nav_title)
    BaseTextView tvNavTitle;
    @BindView(R.id.tv_status)
    BaseTextView tvStatus;
    @BindView(R.id.tv_amount)
    BaseTextView tvAmount;
    @BindView(R.id.tv_loansLine)
    BaseTextView tvLoansLine;
    @BindView(R.id.tv_deadTime)
    BaseTextView tvDeadTime;
    @BindView(R.id.tv_refundTime)
    BaseTextView tvRefundTime;
    @BindView(R.id.tv_orderId)
    BaseTextView tvOrderId;
    @BindView(R.id.iv_licence)
    ImageView ivLicence;
    @BindView(R.id.dragLayout)
    DragLayout dragLayout;
    @BindView(R.id.scrollView)
    NestedScrollView scrollView;

    @Override
    public int getLayoutId() {
        return R.layout.activity_licence;
    }

    @Override
    public void onBaseCreate(@Nullable Bundle savedInstanceState) {
        dragLayout.setListener(this);

        final RefundBean refundBean = (RefundBean) getIntent().getSerializableExtra(Constants.REFUND_BEAN);
        switch (CommonUtils.parseInt(refundBean.getStatus())){
            case 1:
                tvStatus.setText(getString(R.string.finished));
                break;
            case 2:
                tvStatus.setText(getString(R.string.waitCheck));
                break;
            case 3:
                tvStatus.setText(getString(R.string.rejected));
                break;
        }
        tvAmount.setText(refundBean.getAmount()+"元");
        if (!TextUtils.isEmpty(refundBean.getRefund_time())){
            long refundTime = CommonUtils.parseStringToTime(refundBean.getRefund_time(), 0);
            long time = CommonUtils.parseStringToTime(refundBean.getJk_time(),0);
            tvLoansLine.setText(CommonUtils.getDayCounts((refundTime - time)*1d/1000L)+"天");

            tvDeadTime.setText(refundBean.getEnd_time());
        }else{
            tvDeadTime.setText("暂无");
            tvLoansLine.setText("暂无");
        }
        tvRefundTime.setText(refundBean.getRefund_time());

        tvOrderId.setText(refundBean.getOrderid());
        Glide.with(this).load(refundBean.getOrderimg()).crossFade().into(ivLicence);
        ivLicence.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ArrayList<String> list = new ArrayList<String>();
                list.add(refundBean.getOrderimg());
                CommonUtils.startAnimaActivity(LicenceActivity.this,ivLicence,list,0);
            }
        });
    }

    @Override
    public Api onApiCreate() {
        return null;
    }

    @OnClick(R.id.iv_nav_back)
    public void onViewClicked() {
        finish();
    }

    @Override
    public void initTitle() {
        tvNavTitle.setText("查看还款凭证");
    }

    @Override
    public boolean isCanPullDown() {
        return CommonUtils.isReachTop(scrollView);
    }

    @Override
    public boolean isCanPullUp() {
        return CommonUtils.isReachBottom(scrollView);
    }
}
